package vivek.project.pocketmoney.common.controls.ComboDataGridColumn
{
	import flash.events.Event;
	
	import mx.containers.VBox;
	import mx.controls.ComboBox;
	import mx.controls.Label;
	import mx.controls.listClasses.ListData;
	import mx.events.DataGridEvent;
	import mx.events.ListEvent;
	
	import vivek.project.pocketmoney.admin.model.AdminConstants;
	import vivek.project.pocketmoney.common.utils.CommonConstants;

	/**
	 *  Dispatched when the ComboBox contents changes as a result of user
	 *  interaction, when the <code>selectedIndex</code> or
	 *  <code>selectedItem</code> property changes, and, if the ComboBox control
	 *  is editable, each time a keystroke is entered in the box.
	 *
	 *  @eventType mx.events.ListEvent.CHANGE
	 */
	[Event(name="change", type="mx.events.ListEvent")]
	public class MatrixGridTopHeaderComboAS extends VBox
	{
		public function MatrixGridTopHeaderComboAS()
		{
			//trace(new Date().toTimeString()+"\tComboBoxHeaderColumn:ComboBoxHeaderColumn\tStart");
			super();

			horizontalScrollPolicy="off";
			verticalScrollPolicy="off";
			combo.addEventListener(ListEvent.CHANGE, changeHandler);
			//combo.rowCount=15;

			//trace(new Date().toTimeString()+"\tComboBoxHeaderColumn:ComboBoxHeaderColumn\tEnd");
		}
		private var _data:ComboBoxHeaderColumn;
		private var combo:ComboBox=new ComboBox();
		private var labels:Label=new Label();

		override public function get data():Object
		{
			return _data;
		}

		override public function set data(value:Object):void
		{
			//trace(new Date().toTimeString()+"\tMatrixGridTopHeader:data\tstart");
			super.data=value;
			_data=value as ComboBoxHeaderColumn;
			combo.data=value;
			combo.labelFunction=_data.comboLabelFunction;
			combo.listData=value as ListData;
			//_data.width=combo.width;
			//combo.labelField=_data.comboLabelField;
			labels.text=_data.headerText;
			//	combo.itemRenderer=_data.comboBoxItemRenderer;
			//AdvancedDataGrid(combo.addEventListener(AdvancedDataGridEvent.HEADER_RELEASE, sortEventHandler));
			combo.dataProvider=_data.comboBoxDataProvider;
			combo.selectedIndex=_data.selectedIndex;
			//trace(new Date().toTimeString()+"\tMatrixGridTopHeader:data\tEnd");
			//trace("Column end : "+new Date().toTimeString());
		}



		override protected function measure():void
		{
			super.measure();
			//combo.measuredWidth=measuredWidth;
		}

		private function changeHandler(event:Event):void
		{
			data.selectedIndex=combo.selectedIndex;
			data.selectedItem=combo.selectedItem;
			if (combo.selectedItem != CommonConstants.ALL_STRING)
			{
				combo.setStyle("color", "#0000FF");
				setStyle("iconColor", "#0000FF");
			}
			else
			{
				combo.setStyle("color", "#000000")
				setStyle("iconColor", "#000000");
			}
			data.dispatchEvent(event);
		}

		private function init():void
		{
			trace("l");
		}

		private function sortEventHandler(event:DataGridEvent):void
		{
			if (event.itemRenderer == this)
				event.preventDefault();
		}

		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			combo.rowCount=10;
			combo.width=super.width;
			combo.setStyle("cornerRadius", 0);
			if (combo.dropdownWidth <= combo.width)
				combo.dropdownWidth=combo.width;
			else
				combo.dropdownWidth=200;

		}

		override protected function createChildren():void
		{
			super.createChildren();
			addChild(labels);
			addChild(combo);
			//super.titleBar.addChild(_hminimizer);
		}
	}
}